package utils

import (
	"pro-downloader/assets"
	"encoding/json"
	"log"
)

type Configuration struct {
	BaseURL string `json:"base_url"`
	Domain string `json:"domain"`
	DbDriver string `json:"db_driver"`
	DbURL string `json:"db_url"`
	DownloadPath string `json:"download_path"`
}

var configuration *Configuration

//默认初始化
//func init() {
//	log.Println("=======加载json配置文件=======")
//	configFile, _ := os.Open("./static/conf.json")
//	defer configFile.Close()
//
//	decodeFile := json.NewDecoder(configFile)
//	configuration = &Configuration{}
//
//	err := decodeFile.Decode(configuration)
//	if err != nil {
//		panic(err)
//	}
//}

func init() {
	log.Println("==加载json配置文件=======>>>>>>>>>>>>>>")
	data,_ := assets.Asset("static/conf.json")
	configuration = &Configuration{}
	err := json.Unmarshal(data, configuration)
	if err != nil {
		log.Fatalf("Json解析失败:%v", err)
	}
}

func GetBaseURL() string {
	return configuration.BaseURL
}

func GetDomain() string {
	return configuration.Domain
}

func GetDbDriver() string {
	return configuration.DbDriver
}

func GetDbUrl() string {
	return configuration.DbURL
}

func GetDownloadPath() string  {
	return configuration.DownloadPath
}